#ifndef PT_MBUS_H
#define PT_MBUS_H
#include <pt.h>
#include <stdbool.h>
#include <stdint.h>

enum
{
	PT_TOPIC_MOBILE_NET = 0x0,
	PT_TOPIC_MOBILE_DEV = 0x10,
	PT_TOPIC_MOBILE_SIM = 0x20,
	PT_TOPIC_MOBILE_OTA = 0x30,
	PT_TOPIC_POC = 0xE0,
	PT_TOPIC_MAX = 0xFF,
};

typedef int(*pt_mbus_callback_t)(void* arg, void *user_data);

#define SHORT_DATA_MSG_BODY_THRESHOLD   (sizeof(void *))

/// data service message structure type
typedef struct
{
	uint32_t dst_cid;       // Internal use only
	uint16_t len;            /*!< Parameter length */
	uint32_t no_free : 1;     /**< 1: no need to free memory of long msg, 0: need to free memory of long msg */
	uint32_t reserved : 31;
	uint8_t  body[SHORT_DATA_MSG_BODY_THRESHOLD]; /*!< Saving whole short msg body, which length <= SHORT_DATA_MSG_BODY_THRESHOLD.
													   For long msg body which length > SHORT_DATA_MSG_BODY_THRESHOLD,
													   we'll allocate a memroy from heap and save a pointer here.
												  */
}pt_mbus_msg_t;

/**
@brief pt_mbus_init_msg
@param[in,out] msg Message pointer to be initialized
@param[in] body_len Size of message body
@retval Pointer to message body.
*/
uint8_t* pt_mbus_init_msg(pt_mbus_msg_t* msg, uint16_t body_len);

/**
@brief pt_mbus_get_msg_body
@param[in] msg Message pointer
@retval Pointer to message body.
*/
uint8_t* pt_mbus_get_msg_body(pt_mbus_msg_t* msg);

void pt_mbus_handle_with_sleep(uint32_t timeout, bool (*is_sys_sleep)(void));

#include "pt_mbus_subscribe.h"
#include "pt_mbus_publish.h"

#endif
